package com.tongzhou.client;

import net.sf.json.JSONObject;

import com.tongzhou.db.exception.DBException;
import com.tongzhou.tongzhou.order.dao.IOrderDAO;
import com.tongzhou.tongzhou.order.dao.impl.OrderDAO;
import com.tongzhou.tongzhou.order.model.GoodsOrder;
import com.tongzhou.util.Util;

//物流详细
public class ClientDetail {
	IOrderDAO dao=new OrderDAO();
	public String getInfo(String json){
//		订单编号、订单日期、交货日期、纸质、楞别、纸长、纸宽、数量、单价、总价
		JSONObject jsonObject = JSONObject.fromObject( json );
		String companyNum=null;
		Integer oid=null;
		try{
			if(jsonObject.get("companyNum")!=null){
				companyNum=(String) jsonObject.get("companyNum");
			}
			if(jsonObject.get("oid")!=null){
				oid=(Integer) jsonObject.get("oid");
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
		
		StringBuffer str=new StringBuffer();
		if(companyNum==null||oid==null){
			return "{'success':0,'msg':'输入参数有误!'}";
		}else{
			GoodsOrder order=new GoodsOrder();
			order.setCompany_num(companyNum);
			order.setId(oid);
			try {
				GoodsOrder o=dao.getOrdertById(order);
				if(o!=null){
					str.append("{'success':1,'msg':");
					str.append("{'oid':"+o.getId()+",");
					str.append("'orderDate':'"+Util.changeToObj(o.getOrder_date())+"',");
					str.append("'finishDate':'"+Util.changeToObj(o.getFinish_date())+"',");
					str.append("'paper':'"+Util.changeToObj(o.getPaper_name())+"',");
					str.append("'lb':'"+Util.changeToObj(o.getLb())+"',");
					str.append("'paperHeigth':"+o.getPaperHeigth()+",");
					str.append("'paperWidth':"+o.getPaperWidth()+",");
					str.append("'count':"+o.getCount()+",");
					str.append("'price':"+o.getPrice()+"}}");
					
				}else{
					str.append("{'success':0,'msg':'没有对应的物流信息!'}");
				}
				return str.toString();
			} catch (DBException e) {
				e.printStackTrace();
			}
			
		}	
//		String str="{'success':1,'msg':{'oid':123,'orderDate':'2012-11-22','finishDate':'2012-11-24',";
//		str+="'paper':'323','lb':'楞别','paperHeigth':123,'paperWidth':123,'paperWidth':123}}";
		return "{'success':0,'msg':'输入参数有误!'}";
	}
}
